Object.defineProperty(exports, "__esModule", {
    value: !0
}), exports.getAuthorizePhone = void 0;

var t = Object.assign || function(t) {
    for (var e = 1; e < arguments.length; e++) {
        var a = arguments[e];
        for (var o in a) Object.prototype.hasOwnProperty.call(a, o) && (t[o] = a[o]);
    }
    return t;
}, e = require("./login"), a = function(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}(require("./urls")), o = require("./request"), r = require("./staffRelationship"), i = getApp(), n = {
    authorizeStatus: 0,
    switchStatus: 0,
    mobile: null
};

exports.getAuthorizePhone = function() {
    return new Promise(function(e, r) {
        1 !== n.authorizeStatus ? (0, o.post)(a.default.authorizeStatusUrl, {}, {
            silentFail: !1,
            showLoading: !1
        }).then(function(t) {
            var a = t.data.data, o = a.authorizeStatus, r = a.switchStatus, i = a.mobile;
            Object.assign(n, {
                authorizeStatus: o,
                switchStatus: r,
                mobile: i
            }), e({
                authorizeStatus: o,
                switchStatus: r,
                mobile: i
            });
        }, function(t) {
            return r(t);
        }) : e(t({}, n));
    });
}, exports.default = function(u) {
    var s = !(arguments.length > 1 && void 0 !== arguments[1]) || arguments[1];
    return new Promise(function(l, c) {
        (0, e.loginByWechat)().then(function(e) {
            (0, o.post)(a.default.authPhoneUrl, t({
                code: e
            }, u, {
                cardId: i.globalData.cardId
            }), {
                silentFail: !1,
                showLoading: !0
            }).then(function(t) {
                var e = t.data.data.mobile;
                n.authorizeStatus = 1, n.mobile = e, s && (0, r.bindStaffRelationship)(e), l(e);
            }).catch(function(t) {
                return c(t);
            });
        }).catch(function(t) {
            return c(t);
        });
    });
};